package com.whq.knowverywell.task;

import android.content.Context;
import android.os.AsyncTask;

import com.whq.knowverywell.business.http.GetOnePatternProductSalesDataUtil;
import com.whq.knowverywell.business.http.GetProductDataUtil;
import com.whq.knowverywell.business.http.model.ProductSalesReturn;
import com.whq.knowverywell.business.model.Product;
import com.whq.knowverywell.util.LogUtil;

/**
 * 货品查询获取数据
 * @author david
 *
 */
public class GoodsTask extends AsyncTask<String, String, ProductSalesReturn> {
    private final static String TAG = GoodsTask.class.getSimpleName();

    private Context context = null;
    private ResultDataListener listener;
    private String productNo;

    public GoodsTask(Context context, ResultDataListener listener, String productNo) {
        this.context = context;
        this.listener = listener;
        this.productNo = productNo;
    }

    @Override
    protected ProductSalesReturn doInBackground(String... params) {
        if (this.context == null) {
            return null;
        }

        LogUtil.i(TAG, "productNo[" + productNo + "]");

        ProductSalesReturn goodsResult = null;
        Product product = GetProductDataUtil.getDetail(context, productNo);
        if (product == null) {
            return null;
        }
        LogUtil.i(
                TAG,
                "product code[" + product.getCode() + "]" + " imgurl[" + product.getImgUrl() + "]" + " name["
                        + product.getName() + "]" + " price[" + product.getPrice() + "]" + " shellFabric["
                        + product.getShellFabric() + "]");
        goodsResult = GetOnePatternProductSalesDataUtil.getList(context, productNo);

        return goodsResult;
    }

    @Override
    protected void onPostExecute(ProductSalesReturn huizongResult) {
        this.listener.handleData(huizongResult);
    }

    public interface ResultDataListener {
        public void handleData(ProductSalesReturn huizongResult);
    }
}
